/*
 * The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use
 * this file except in compliance with the License. You can obtain a copy of the license at glassfish/bootstrap/legal/CDDLv1.0.txt or
 * https://glassfish.dev.java.net/public/CDDLv1.0.html. See the License for the specific language governing permissions and limitations
 * under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at
 * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets
 * "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] Copyright 2005 Sun Microsystems,
 * Inc. All rights reserved. Portions Copyright Apache Software Foundation.
 */

package jmine.tec.web.servlet.delegate;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;

/**
 * Provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to
 * a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object.
 * 
 * @see javax.servlet.ServletRequest
 */
public class ServletRequestWrapper implements ServletRequest {
    private final ServletRequest request;

    /**
     * Creates a ServletRequest adaptor wrapping the given request object.
     * 
     * @param request the {@link ServletRequest}
     */
    public ServletRequestWrapper(ServletRequest request) {
        if (request == null) {
            throw new IllegalArgumentException("Request cannot be null");
        }
        this.request = request;
    }

    /**
     * {@inheritDoc}
     */
    public ServletRequest getRequest() {
        return this.request;
    }

    /**
     * {@inheritDoc}
     */
    public Object getAttribute(String name) {
        return this.request.getAttribute(name);
    }

    /**
     * {@inheritDoc}
     */
    public Enumeration getAttributeNames() {
        return this.request.getAttributeNames();
    }

    /**
     * {@inheritDoc}
     */
    public String getCharacterEncoding() {
        return this.request.getCharacterEncoding();
    }

    /**
     * {@inheritDoc}
     */
    public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException {
        this.request.setCharacterEncoding(enc);
    }

    /**
     * {@inheritDoc}
     */
    public int getContentLength() {
        return this.request.getContentLength();
    }

    /**
     * {@inheritDoc}
     */
    public String getContentType() {
        return this.request.getContentType();
    }

    /**
     * {@inheritDoc}
     */
    public ServletInputStream getInputStream() throws IOException {
        return this.request.getInputStream();
    }

    /**
     * {@inheritDoc}
     */
    public String getParameter(String name) {
        return this.request.getParameter(name);
    }

    /**
     * {@inheritDoc}
     */
    public Map getParameterMap() {
        return this.request.getParameterMap();
    }

    /**
     * {@inheritDoc}
     */
    public Enumeration getParameterNames() {
        return this.request.getParameterNames();
    }

    /**
     * {@inheritDoc}
     */
    public String[] getParameterValues(String name) {
        return this.request.getParameterValues(name);
    }

    /**
     * {@inheritDoc}
     */
    public String getProtocol() {
        return this.request.getProtocol();
    }

    /**
     * {@inheritDoc}
     */
    public String getScheme() {
        return this.request.getScheme();
    }

    /**
     * {@inheritDoc}
     */
    public String getServerName() {
        return this.request.getServerName();
    }

    /**
     * {@inheritDoc}
     */
    public int getServerPort() {
        return this.request.getServerPort();
    }

    /**
     * {@inheritDoc}
     */
    public BufferedReader getReader() throws IOException {
        return this.request.getReader();
    }

    /**
     * {@inheritDoc}
     */
    public String getRemoteAddr() {
        return this.request.getRemoteAddr();
    }

    /**
     * {@inheritDoc}
     */
    public String getRemoteHost() {
        return this.request.getRemoteHost();
    }

    /**
     * {@inheritDoc}
     */
    public void setAttribute(String name, Object o) {
        this.request.setAttribute(name, o);
    }

    /**
     * {@inheritDoc}
     */
    public void removeAttribute(String name) {
        this.request.removeAttribute(name);
    }

    /**
     * {@inheritDoc}
     */
    public Locale getLocale() {
        return this.request.getLocale();
    }

    /**
     * {@inheritDoc}
     */
    public Enumeration getLocales() {
        return this.request.getLocales();
    }

    /**
     * {@inheritDoc}
     */
    public boolean isSecure() {
        return this.request.isSecure();
    }

    /**
     * {@inheritDoc}
     */
    public RequestDispatcher getRequestDispatcher(String path) {
        return this.request.getRequestDispatcher(path);
    }

    /**
     * {@inheritDoc}
     * @deprecated
     */
    public String getRealPath(String path) {
        return this.request.getRealPath(path);
    }

    /**
     * {@inheritDoc}
     */
    public int getRemotePort() {
        return this.request.getRemotePort();
    }

    /**
     * {@inheritDoc}
     */
    public String getLocalName() {
        return this.request.getLocalName();
    }

    /**
     * {@inheritDoc}
     */
    public String getLocalAddr() {
        return this.request.getLocalAddr();
    }

    /**
     * {@inheritDoc}
     */
    public int getLocalPort() {
        return this.request.getLocalPort();
    }

}
